/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Trp_provinciaDAOImpl implements orm.dao.Trp_provinciaDAO {
	public Trp_provincia loadTrp_provinciaByORMID(int pr_id_prov) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_provinciaByORMID(session, pr_id_prov);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia getTrp_provinciaByORMID(int pr_id_prov) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_provinciaByORMID(session, pr_id_prov);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByORMID(int pr_id_prov, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_provinciaByORMID(session, pr_id_prov, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia getTrp_provinciaByORMID(int pr_id_prov, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return getTrp_provinciaByORMID(session, pr_id_prov, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByORMID(PersistentSession session, int pr_id_prov) throws PersistentException {
		try {
			return (Trp_provincia) session.load(orm.Trp_provincia.class, new Integer(pr_id_prov));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia getTrp_provinciaByORMID(PersistentSession session, int pr_id_prov) throws PersistentException {
		try {
			return (Trp_provincia) session.get(orm.Trp_provincia.class, new Integer(pr_id_prov));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByORMID(PersistentSession session, int pr_id_prov, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_provincia) session.load(orm.Trp_provincia.class, new Integer(pr_id_prov), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia getTrp_provinciaByORMID(PersistentSession session, int pr_id_prov, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Trp_provincia) session.get(orm.Trp_provincia.class, new Integer(pr_id_prov), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia[] listTrp_provinciaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_provinciaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia[] listTrp_provinciaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return listTrp_provinciaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia[] listTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_provincia as Trp_provincia");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Trp_provincia[]) list.toArray(new Trp_provincia[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia[] listTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_provincia as Trp_provincia");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Trp_provincia[]) list.toArray(new Trp_provincia[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_provinciaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return loadTrp_provinciaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Trp_provincia[] trp_provincias = listTrp_provinciaByQuery(session, condition, orderBy);
		if (trp_provincias != null && trp_provincias.length > 0)
			return trp_provincias[0];
		else
			return null;
	}
	
	public Trp_provincia loadTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Trp_provincia[] trp_provincias = listTrp_provinciaByQuery(session, condition, orderBy, lockMode);
		if (trp_provincias != null && trp_provincias.length > 0)
			return trp_provincias[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTrp_provinciaByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_provinciaByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_provinciaByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Basededatosv5PersistentManager.instance().getSession();
			return iterateTrp_provinciaByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_provincia as Trp_provincia");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTrp_provinciaByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Trp_provincia as Trp_provincia");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia createTrp_provincia() {
		return new orm.Trp_provincia();
	}
	
	public boolean save(orm.Trp_provincia trp_provincia) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().saveObject(trp_provincia);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Trp_provincia trp_provincia) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().deleteObject(trp_provincia);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_provincia trp_provincia)throws PersistentException {
		try {
			if(trp_provincia.getRegion() != null) {
				trp_provincia.getRegion().trp_provincia.remove(trp_provincia);
			}
			
			orm.Trp_colegio[] lTrp_colegios = trp_provincia.trp_colegio.toArray();
			for(int i = 0; i < lTrp_colegios.length; i++) {
				lTrp_colegios[i].setProvincia(null);
			}
			return delete(trp_provincia);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Trp_provincia trp_provincia, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(trp_provincia.getRegion() != null) {
				trp_provincia.getRegion().trp_provincia.remove(trp_provincia);
			}
			
			orm.Trp_colegio[] lTrp_colegios = trp_provincia.trp_colegio.toArray();
			for(int i = 0; i < lTrp_colegios.length; i++) {
				lTrp_colegios[i].setProvincia(null);
			}
			try {
				session.delete(trp_provincia);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Trp_provincia trp_provincia) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().refresh(trp_provincia);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Trp_provincia trp_provincia) throws PersistentException {
		try {
			orm.Basededatosv5PersistentManager.instance().getSession().evict(trp_provincia);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Trp_provincia loadTrp_provinciaByCriteria(Trp_provinciaCriteria trp_provinciaCriteria) {
		Trp_provincia[] trp_provincias = listTrp_provinciaByCriteria(trp_provinciaCriteria);
		if(trp_provincias == null || trp_provincias.length == 0) {
			return null;
		}
		return trp_provincias[0];
	}
	
	public Trp_provincia[] listTrp_provinciaByCriteria(Trp_provinciaCriteria trp_provinciaCriteria) {
		return trp_provinciaCriteria.listTrp_provincia();
	}
}
